package test8;

import java.util.Scanner;

public class test {
    private static Scanner in;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        int n;
        Integer a;
        while (true) {
            n = in.nextInt();
            ArrayListIntegerStack arrayIntegerStack = new ArrayListIntegerStack(n);
            for (int i = 0; i < n; i++) {
                a = in.nextInt();
                a= arrayIntegerStack.push(a);
                System.out.println(a);
            }
            System.out.println(arrayIntegerStack.peek() + "," + arrayIntegerStack.empty() + "," + arrayIntegerStack.size());
            System.out.println(arrayIntegerStack.getArrayList());
            n = in.nextInt();
            for (int i = 0; i < n; i++) {
                System.out.println(arrayIntegerStack.pop());
            }
            System.out.println(arrayIntegerStack.peek() + "," + arrayIntegerStack.empty() + "," + arrayIntegerStack.size());
            System.out.println(arrayIntegerStack.getArrayList());
        }
    }
}
